/*
* This file is part of the Plasix Framework Library.
*
* Copyright (C) 2014 Plasix Engine
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include <gl/glut.h>

/*
 * Provides a demonstration of a basic glut (freeglut) window. This template can
 * be utilized to generate prototypes for OpenGL-based applications.
 */
const char* WINDOW_TITLE = "Glut Window";
const int WINDOW_WIDTH = 600;
const int WINDOW_HEIGHT = 400;
GLint g_glutWindowIdentifier;

void g_init() {
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
}

void g_glutReshapeFunc(int width, int height) {
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glViewport(0, 0, width, height);
    if ( height == 0 ) height = 1;
    gluPerspective(45.0f, static_cast<float>(width) / static_cast<float>(height), 0.1f, 100.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}

void g_glutDisplayFunc() {
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
    gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

    glPopMatrix();
    glFlush();
}

void g_glutKeyboardFunc(unsigned char key, int x, int y) {
    glutPostRedisplay();
}

void g_glutMouseFunc(int x, int y) {
    glutPostRedisplay();
}

void g_glutMouseFunc(int button, int state, int x, int y) {
    glutPostRedisplay();
}

int main(int argc, char* argv[]) {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA);
    glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);

    g_glutWindowIdentifier = glutCreateWindow(WINDOW_TITLE);
    glutMouseFunc(g_glutMouseFunc);
    glutMotionFunc(g_glutMouseFunc);
    glutDisplayFunc(g_glutDisplayFunc);
    glutReshapeFunc(g_glutReshapeFunc);
    glutKeyboardFunc(g_glutKeyboardFunc);

    g_init();

    glutMainLoop();
}
